package com.js.gate.server.config;

import com.js.gate.server.route.MyRouteLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author ygl
 * @create 2018-10-26
 * @DESCRIPTION
 **/
@Configuration
public class GateConfig {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    ZuulProperties zuulProperties;

    @Autowired
    ServerProperties serverProperties;

    @Autowired
    DispatcherServletRegistrationBean dispatcherServletRegistrationBean;

    /**
     * xssFilter注册
     */
//    @Bean
//    public FilterRegistrationBean xssFilterRegistration() {
//        XssFilter xssFilter = new XssFilter();
//        FilterRegistrationBean registration = new FilterRegistrationBean(xssFilter);
//        registration.addUrlPatterns("/*");
//        registration.setOrder(Integer.MIN_VALUE);
//        return registration;
//    }

    @Bean
    public MyRouteLocator myRouteLocator() {
        MyRouteLocator myRouteLocator = new MyRouteLocator(dispatcherServletRegistrationBean.getPrefix(), this.zuulProperties);
        myRouteLocator.setRedisTemplate(this.redisTemplate);
        return myRouteLocator;
    }
}
